---
title: Configuration.connect()
api: Configuration.connect
---

## Description

<Summary/>

<FilterDiagram
  name="connect"
  input="Data"
  output="Data"
/>

A _connect_ filter does the following:

- It establishes a TCP or UDP connection to a remote host specified in the _target_ parameter
- Input _Data_ stream to the filter is sent to that host after the connection is established
- _Data_ stream received from that host comes out from the filter's output

### Target address

The target address to connect to is given by the _target_ parameter. It can be a string in form of `"<host>:<port>"` or a function that returns that string, where _host_ can be an IP address or a domain name and _port_ must be a valid port number.

> When using an IPv6 address, wrap it inside a pair of brackets. For example, `"[::1]:8080"`.

### Outbound data buffer

No limit is set to how fast input _Data_ can go into a _connect_ filter, but an outgoing TCP connection does have a limit depending on the network condition. When outgoing traffic is too slow and incoming traffic is too fast, _Data_ will be backed up in the filter's internal buffer.

By default, the buffer can grow unlimitedly. You can set a limit to how much data is allowed to stay in memory by option _bufferLimit_ in the _options_ parameter. It can be a number in bytes or a string with a unit suffix such as `'k'`, `'m'`, `'g'` and `'t'`.

When data in the buffer goes over that limit, the overflowed data is discarded and you will see an error message from the standard error:

```
Outbound: xxx to host = xxx port = nnn buffer overflow, size = nnn
```

## Syntax

``` js
pipy()
  .pipeline()
  .connect(target)

pipy()
  .pipeline()
  .connect(
    () => getTarget()
  )

pipy()
  .pipeline()
  .connect(
    () => getTarget(),
    {
      bufferLimit,
      retryCount,
      retryDelay,
      connectTimeout,
      readTimeout,
      writeTimeout,
      idleTimeout,
    }
  )
```

## Parameters

<Parameters/>

## Example

``` js
pipy()

  .listen(8000)      // Accept connections via port 8000
  .dump('>>>')       // Dump all outgoing data
  .connect(
    'localhost:8080' // Connect to localhost:8080
  )
  .dump('<<<')       // Dump all received data
```

## See Also

* [Configuration](/reference/api/Configuration)
* [connectTLS()](/reference/api/Configuration/connectTLS)
